from rest_framework.serializers import ModelSerializer
from .models import ProvinceModel, CityModel, AreaModel
from department.models import HospitalModel,DoctorModel
from rest_framework import serializers





class SearchDoctorListSerializer(ModelSerializer):
  title =serializers.CharField(source='title.name')
  htitle = serializers.SerializerMethodField()
  def get_htitle(self, obj):
    return obj.hospital.title.name

  hname = serializers.CharField(source='hospital.name')

  department = serializers.CharField(source='department.name')

  goodat = serializers.SerializerMethodField()

  def get_goodat(self, obj):
    return ", ".join(i.name for i in obj.goodat.all())

  label = serializers.SerializerMethodField()

  def get_label(self, obj):
    return [i.name for i in obj.label.all()]

  class Meta:
    model = DoctorModel
    fields = ['id', 'name','title','htitle','department','hname','goodat','rate','reply','label','price']



class DoctorHomeDataSerializer(ModelSerializer):
  title =serializers.CharField(source='title.name')
  htitle = serializers.SerializerMethodField()
  def get_htitle(self, obj):
    return obj.hospital.title.name

  hname = serializers.CharField(source='hospital.name')

  department = serializers.CharField(source='department.name')


  label = serializers.SerializerMethodField()

  def get_label(self, obj):
    return [i.name for i in obj.label.all()]

  class Meta:
    model = DoctorModel
    fields = ['id', 'name','title','htitle','department','hname','rate','reply','label','price','intro','reply_time']